/**
 *@Description 清单首页
 *@Author ming
 *@Date 2016-09-28
 */
var excelCtrl  = new XFApp.client();
XFApp.client.prototype.excel = {
	successCode : "10000",
	page : null,
	urlItems : {
		queryByPageURL : basePath+"/nt/excel/getPage",
		downLoadURL : basePath+"/nt/excel/downloadExcel"
	},
	downloadExcel: function(fileName){

		_this = this;
		var url = _this.urlItems.downLoadURL+'?fileName='+fileName;
		$("body").append("<iframe id='excelID' src='" + url +"' frameborder=0 width=0 height=0 style='display:none'></iframe>");
	},

	queryPage : function(){
		_this = this;
		if(!!_this.page){
			_this.page.page("remote",0,$('#searchForm').serialize());
		}else{
		_this.page = $("#page").page({
			pageSize : 10,
			currentPageIndex : Number($("#currentPageIndex").val())-1,
			remote: {
				url: _this.urlItems.queryByPageURL,
		        params: $('#searchForm').serialize(), 
		        success: function (data, pageIndex) {
		        	$("#currentPageIndex").val(data.result.pageNo);
		        	if(data.code==_this.successCode){
		        		var pageResult = data.result;
		        		if(null == data 
								|| null == data.result 
									|| null == data.result.itemList
										|| data.result.itemList.length < 1){
		        			$("#page_grid").html('<tr><td align="center" colspan="11">暂无数据</td></tr>');
		        		}else{
		        			for(var index in pageResult.itemList){
		        				var element = pageResult.itemList[index];
		        				element["seqNum"]=parseInt(pageResult.pageSize)*(parseInt(pageResult.pageNo)-1)+parseInt(index)+1;
		        			}
		        			$("#page_grid").html($("#dataTmp").render(pageResult.itemList));
		        		}
		        	}else{
		        		window.webDialogUtil.alert("提示","操作失败");
		        	}
		        },
		        error : function(){
		        	window.webDialogUtil.alert("提示","操作失败");
		        }
			},
			firstBtnText : '首页',
			lastBtnText : '尾页',
			prevBtnText : '上一页',
			nextBtnText : '下一页',
			showInfo : true,
			showJump : true,
			jumpBtnText : '跳转',
			showPageSizes : true,
			infoFormat : '共{pageCount}页,{total}项'
		});
		}
	},
	bindEvent: function(){
		var _this = this;
		$('#searchButton').on('click',function(){
			excelCtrl.excel.queryPage();
		});
	}
	
};

$(function(){
	excelCtrl.excel.queryPage();
	excelCtrl.excel.bindEvent();
});